if !exists(param.A)
  M291 S1 T0 R"Use Auto Calibration macro" P"Using separate calibration macros may cause issues.<br>Please use the Auto Calibration macro"
  abort "Error: Auto Calibration macro required."



;====Probe with Nozzle====

G90
G1 F18000 X0 Y80 Z5 F18000

G91
M98 P"0:/sys/nozzleprobe.g" Z1
var zn = move.axes[2].machinePosition
G1 Z20






;====Probe with Z - Probe====
M98 R1 P"0:/sys/attachedcheck.g" ; make sure probe is conected, pick if negative and leave relay active
M558 K0 P8 C"1.io4.in" H5 F100 T18000              ; define Z probe parameters
M98 P"0:/sys/user/actions/ProbeOffset.g"

G90                 ; absolute positioning
G1 X{0 - sensors.probes[0].offsets[0]} Y{80 - sensors.probes[0].offsets[1]} F18000

G91
G38.2 K0 Z0 ; Probe Z
G4 P260
var zp1 = move.axes[2].machinePosition
G1 Z5

G38.2 K0 Z0 ; Probe Z
G4 P260
var zp2 = move.axes[2].machinePosition
G1 Z5

G38.2 K0 Z0 ; Probe Z
G4 P260
var zp3 = move.axes[2].machinePosition
G1 Z5


var zp =  (var.zp1 + var.zp2 + var.zp3)/3


var dd = var.zp - var.zn

echo "New Z offset is: "^{var.dd}^" mm"


;======= Additional offset ======= Increase (+) to lower, Decrease (-) to raise

set global.zOffset = var.dd - {0.0}  ; Apply babystepping to zOffset (add for less Z offset)

;======= Additional offset =======
echo >"0:/sys/user/actions/ProbeOffset.g" "G31 P500 X0 Y28.50 Z"^{global.zOffset}^" ; Set Z probe trigger value, offset and trigger height"
M98 P"0:/sys/user/actions/ProbeOffset.g"

echo >"0:/sys/user/variables/ZOffset.g" "set global.zOffset = "^{global.zOffset}

G30           ; Home bed using probe to update datum